<!doctype html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="linux,centos6,nodejs," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="CentOS6安装Node.Js环境背景描述

近期将前端代码工程化，使用webbpack构建，对前端开发来讲确实带来的新的体验。
依赖包、模块、打包、构建等在后端开发才遇到的概念，前端工程化也在使用，前后端开发分离、模块化、组件化是一种趋势。
因此在使用Jenkins做持续集成、构建时，也必须构建前端代码，而前端代码构建又依赖NodeJs环境，而安装过程一波三折~。">
<meta property="og:type" content="article">
<meta property="og:title" content="CentOS6安装Node.Js">
<meta property="og:url" content="https://vector-ding.coding.me/技术/CentOS6安装Node-Js/index.html">
<meta property="og:site_name" content="Vector's Notes">
<meta property="og:description" content="CentOS6安装Node.Js环境背景描述

近期将前端代码工程化，使用webbpack构建，对前端开发来讲确实带来的新的体验。
依赖包、模块、打包、构建等在后端开发才遇到的概念，前端工程化也在使用，前后端开发分离、模块化、组件化是一种趋势。
因此在使用Jenkins做持续集成、构建时，也必须构建前端代码，而前端代码构建又依赖NodeJs环境，而安装过程一波三折~。">
<meta property="og:image" content="https://vector-ding.coding.me/技术/CentOS6安装Node-Js/nodejs-download-sourcecode.png">
<meta property="og:image" content="https://vector-ding.coding.me/技术/CentOS6安装Node-Js/nodejs-download-linux-binary.png">
<meta property="og:updated_time" content="2017-03-02T02:53:58.871Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="CentOS6安装Node.Js">
<meta name="twitter:description" content="CentOS6安装Node.Js环境背景描述

近期将前端代码工程化，使用webbpack构建，对前端开发来讲确实带来的新的体验。
依赖包、模块、打包、构建等在后端开发才遇到的概念，前端工程化也在使用，前后端开发分离、模块化、组件化是一种趋势。
因此在使用Jenkins做持续集成、构建时，也必须构建前端代码，而前端代码构建又依赖NodeJs环境，而安装过程一波三折~。">
<meta name="twitter:image" content="https://vector-ding.coding.me/技术/CentOS6安装Node-Js/nodejs-download-sourcecode.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '6378305291301160000',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://vector-ding.coding.me/技术/CentOS6安装Node-Js/"/>





  <title> CentOS6安装Node.Js | Vector's Notes </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">Vector's Notes</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
    
      <p class="site-subtitle"></p>
    
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-algorithm">
          <a href="/categories/algorithm/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-superscript"></i> <br />
            
            Algorithm
          </a>
        </li>
      
        
        <li class="menu-item menu-item-java">
          <a href="/categories/java/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-coffee"></i> <br />
            
            Java
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="https://vector-ding.coding.me/技术/CentOS6安装Node-Js/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="vector.ding">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/assets/img/vector.ding.jpg">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="Vector's Notes">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="Vector's Notes" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                CentOS6安装Node.Js
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-02-19T13:00:46+08:00">
                2017-02-19
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/技术/" itemprop="url" rel="index">
                    <span itemprop="name">技术</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/技术/CentOS6安装Node-Js/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="技术/CentOS6安装Node-Js/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="CentOS6安装Node-Js环境"><a href="#CentOS6安装Node-Js环境" class="headerlink" title="CentOS6安装Node.Js环境"></a>CentOS6安装Node.Js环境</h1><p>背景描述</p>
<blockquote>
<p>近期将前端代码工程化，使用<code>webbpack</code>构建，对前端开发来讲确实带来的新的体验。
依赖包、模块、打包、构建等在后端开发才遇到的概念，前端工程化也在使用，前后端开发分离、模块化、组件化是一种趋势。
因此在使用Jenkins做持续集成、构建时，也必须构建前端代码，而前端代码构建又依赖<code>NodeJs</code>环境，而安装过程一波三折~。</p>
</blockquote>
<a id="more"></a>
<p>Linux上安装软件大致分为三种方式，三种方式各有优缺点</p>
<ul>
<li>包管理安装</li>
<li>源码编译安装（个人不推荐）</li>
<li>下载binary安装包，解压配置环境变量（类似windows上的绿色免安装版）</li>
</ul>
<h2 id="1-yum软件包管理器安装"><a href="#1-yum软件包管理器安装" class="headerlink" title="1. yum软件包管理器安装"></a>1. yum软件包管理器安装</h2><p>安装脚本
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">yum install nodejs</div></pre></td></tr></table></figure></p>
<p>安装结果验证脚本，输出版本号即可
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">node -v</div><div class="line">v0.10.46</div></pre></td></tr></table></figure></p>
<p>这种方式基本不会出错，非常简单。但问题是<code>v0.10.46</code>这个是什么版本号，NodeJs官网版本号是6、7开头的，<code>yum</code>你在逗我吗？执行构建命令果然会报错。顺便提一下包管理器安装的软件，如果软件不是特别重要，版本一般都不可靠，因此喜欢折腾的同学们请继续吧~</p>
<p>附: yum卸载node命令
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">yum remove nodejs</div></pre></td></tr></table></figure></p>
<h2 id="2-源码编译安装"><a href="#2-源码编译安装" class="headerlink" title="2. 源码编译安装"></a>2. 源码编译安装</h2><p>注意编译需要安装<code>gcc</code>, <code>make</code>等必须的的软件，如未安装，请先执行以下脚本</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">yum -y install gcc make gcc-c++ openssl-devel wget</div></pre></td></tr></table></figure>
<ol>
<li><p>源码下载</p>
<p> Node.Js官网下载地址: <a href="https://nodejs.org/en/download/" target="_blank" rel="external">https://nodejs.org/en/download/</a>
 <img src="/技术/CentOS6安装Node-Js/nodejs-download-sourcecode.png" alt="nodejs-download-sourcecode"></p>
<p> 鼠标右键 | 复制链接地址(<a href="https://nodejs.org/dist/v6.9.5/node-v6.9.5.tar.gz" target="_blank" rel="external">https://nodejs.org/dist/v6.9.5/node-v6.9.5.tar.gz</a>)</p>
<p> 执行命令</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">wget https://nodejs.org/dist/v6.9.5/node-v6.9.5.tar.gz</div></pre></td></tr></table></figure>
</li>
<li><p>源码解压</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar -zvxf node-v6.9.5.tar.gz</div></pre></td></tr></table></figure>
</li>
<li><p>编译安装</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span> node-v6.9.5</div><div class="line">./configure</div><div class="line">make &amp;&amp; make install</div></pre></td></tr></table></figure>
</li>
</ol>
<p>编译过程中报错了，好像是源码文件的错误，能力不及，解决不了，如果又遇到报错的同学，不想折腾，我们继续看第三种安装方式。</p>
<h2 id="3-二进制文件安装"><a href="#3-二进制文件安装" class="headerlink" title="3. 二进制文件安装"></a>3. 二进制文件安装</h2><ol>
<li><p>二进制文件下载</p>
<p> Node.Js官网下载地址: <a href="https://nodejs.org/en/download/" target="_blank" rel="external">https://nodejs.org/en/download/</a>
 <img src="/技术/CentOS6安装Node-Js/nodejs-download-linux-binary.png" alt="nodejs-download-linux-binary"></p>
<p> 选择操作系统位数 | 鼠标右键 | 复制链接地址(<a href="https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-x64.tar.xz" target="_blank" rel="external">https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-x64.tar.xz</a>)</p>
<p> 执行命令</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">wget https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-x64.tar.xz</div></pre></td></tr></table></figure>
</li>
<li><p>解压安装包</p>
<p> 安装包为<code>xz</code>格式文件，先安装<code>xz</code>，一条命令即可:</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">yum intsall xz</div></pre></td></tr></table></figure>
<p> 解压命令</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">xz <span class="_">-d</span> https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-x64.tar.xz</div><div class="line">tar -xvf https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-x64.tar</div></pre></td></tr></table></figure>
</li>
<li><p>配置环境变量</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">cd</span> node-v6.9.5-linux-x64</div><div class="line"><span class="built_in">pwd</span></div><div class="line"></div><div class="line"><span class="comment"># 拷贝pwd回显的路径 $&#123;NODE_HOME&#125;</span></div><div class="line">vim /etc/profile</div><div class="line"><span class="built_in">export</span> NODE_HOME=<span class="string">"<span class="variable">$&#123;NODE_HOME&#125;</span>"</span></div><div class="line"><span class="built_in">export</span> PATH=<span class="string">"<span class="variable">$PATH</span>:<span class="variable">$NODE_HOME</span>/bin"</span></div><div class="line"></div><div class="line"><span class="comment"># 退出vim,刷新环境更变量</span></div><div class="line"><span class="built_in">source</span> /etc/profile</div><div class="line"></div><div class="line"><span class="comment"># 验证安装结果</span></div><div class="line">node -v</div><div class="line">npm -v</div></pre></td></tr></table></figure>
</li>
</ol>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/linux/" rel="tag"># linux</a>
          
            <a href="/tags/centos6/" rel="tag"># centos6</a>
          
            <a href="/tags/nodejs/" rel="tag"># nodejs</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/uncategorized/Linux批量杀死进程脚本/" rel="next" title="Linux批量杀死进程脚本">
                <i class="fa fa-chevron-left"></i> Linux批量杀死进程脚本
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/技术/前端/vue2/Vue2组件通信之事件传递/" rel="prev" title="Vue2组件通信之事件传递">
                Vue2组件通信之事件传递 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="技术/CentOS6安装Node-Js/"
           data-title="CentOS6安装Node.Js" data-url="https://vector-ding.coding.me/技术/CentOS6安装Node-Js/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/assets/img/vector.ding.jpg"
               alt="vector.ding" />
          <p class="site-author-name" itemprop="name">vector.ding</p>
          <p class="site-description motion-element" itemprop="description">Elegant Coding</p>
        </div>
        <nav class="site-state motion-element">
        
          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">9</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">9</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">9</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#CentOS6安装Node-Js环境"><span class="nav-number">1.</span> <span class="nav-text">CentOS6安装Node.Js环境</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-yum软件包管理器安装"><span class="nav-number">1.1.</span> <span class="nav-text">1. yum软件包管理器安装</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-源码编译安装"><span class="nav-number">1.2.</span> <span class="nav-text">2. 源码编译安装</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-二进制文件安装"><span class="nav-number">1.3.</span> <span class="nav-text">3. 二进制文件安装</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">vector.ding</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"vector-ding"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  












  
  

  

  

  

  

</body>
</html>
